package com.archstoday.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.archstoday.R;
import com.archstoday.entity.ScreenEntity;
import com.archstoday.view.AutoNewLineLayout;
import com.base.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 筛选
 */
public class ScreenUtils {
    private static String mScreenType, mScreenArea, mScreenStatus,
            mScreenHot, mScreenLevel, mScreenLiness, mScreenOrg, mScreenTime;
    private static String mScreenTypeValue, mScreenAreaValue, mScreenStatusValue,
            mScreenHotValue, mScreenLevelValue, mScreenLinessValue,
            mScreenOrgValue, mScreenTimeValue;

    public static String mScreenTypeBefor, mScreenAreaBefor, mScreenStatusBefor,
            mScreenHotBefor, mScreenLevelBefor, mScreenLinessBefor, mScreenOrgBefor,
            mScreenTimeBefor;

    public static void addScreen(Context context, LinearLayout layout, ScreenEntity data) {
        layout.removeAllViews();
        for (int i = 0; i < data.getData().size(); i++) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_screen_layout, null);
            TextView titleTv = (TextView) view.findViewById(R.id.item_screen_title_tv);
            AutoNewLineLayout autoLayout = (AutoNewLineLayout) view.findViewById(R.id.item_screen_layout);

            titleTv.setText(data.getData().get(i).getLabel());
            final List<TextView> texts = new ArrayList<>();
            autoLayout.removeAllViews();
            final String type = data.getData().get(i).getValue();
            for (int j = 0; j < data.getData().get(i).getSysDictList().size(); j++) {
                View item = LayoutInflater.from(context).inflate(R.layout.item_screen, null);
                TextView text = (TextView) item.findViewById(R.id.item_tv);

                text.setText(data.getData().get(i).getSysDictList().get(j).getLabel());
                text.setTag(data.getData().get(i).getSysDictList().get(j));
                texts.add(text);

                if (StringUtil.equest(type, "type")) {
                    if (StringUtil.equest(mScreenTypeBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "area")) {
                    if (StringUtil.equest(mScreenAreaBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "status")) {
                    if (StringUtil.equest(mScreenStatusBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "hot")) {
                    if (StringUtil.equest(mScreenHotBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "level")) {
                    if (StringUtil.equest(mScreenLevelBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "timeLiness")) {
                    if (StringUtil.equest(mScreenLinessBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "releaseOrg")) {
                    if (StringUtil.equest(mScreenOrgBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                } else if (StringUtil.equest(type, "releaseTime")) {
                    if (StringUtil.equest(mScreenTimeBefor,
                            data.getData().get(i).getSysDictList().get(j).getValue())) {
                        text.setSelected(true);
                    } else {
                        text.setSelected(false);
                    }
                }

                text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        for (int i = 0; i < texts.size(); i++) {
                            if (texts.get(i) == view) {
                                texts.get(i).setSelected(!texts.get(i).isSelected());
                            } else {
                                texts.get(i).setSelected(false);
                            }
                        }

                        if (StringUtil.equest(type, "type")) {
                            mScreenType = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenTypeValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "area")) {
                            mScreenArea = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenAreaValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "status")) {
                            mScreenStatus = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenStatusValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "hot")) {
                            mScreenHot = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenHotValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "level")) {
                            mScreenLevel = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenLevelValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "timeLiness")) {
                            mScreenLiness = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenLinessValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "releaseOrg")) {
                            mScreenOrg = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenOrgValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        } else if (StringUtil.equest(type, "releaseTime")) {
                            mScreenTime = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getValue() : null;
                            mScreenTimeValue = view.isSelected() ?
                                    ((ScreenEntity.DataBean.SysDictListBean) view.getTag()).getLabel() : null;
                        }
                    }
                });
                autoLayout.addView(item);
            }
            layout.addView(view);
//            }
        }
    }

    public static void setmScreenType(String mScreenType) {
        mScreenType = mScreenType;
    }

    public static String getmScreenType() {
        return mScreenType;
    }

    public static void setmScreenArea(String mScreenArea) {
        mScreenArea = mScreenArea;
    }

    public static String getmScreenArea() {
        return mScreenArea;
    }

    public static void setmScreenStatus(String mScreenStatus) {
        mScreenStatus = mScreenStatus;
    }

    public static String getmScreenStatus() {
        return mScreenStatus;
    }

    public static String getmScreenHot() {
        return mScreenHot;
    }

    public static void setmScreenHot(String mScreenHot) {
        ScreenUtils.mScreenHot = mScreenHot;
    }

    public static String getmScreenLevel() {
        return mScreenLevel;
    }

    public static void setmScreenLevel(String mScreenLevel) {
        ScreenUtils.mScreenLevel = mScreenLevel;
    }

    public static String getmScreenTime() {
        return mScreenTime;
    }

    public static void setmScreenTime(String mScreenTime) {
        ScreenUtils.mScreenTime = mScreenTime;
    }

    public static String getmScreenOrg() {
        return mScreenOrg;
    }

    public static void setmScreenOrg(String mScreenOrg) {
        ScreenUtils.mScreenOrg = mScreenOrg;
    }

    public static String getmScreenLiness() {
        return mScreenLiness;
    }

    public static void setmScreenLiness(String mScreenLiness) {
        ScreenUtils.mScreenLiness = mScreenLiness;
    }

    public static void setmScreenTypeValue(String mScreenTypeValue) {
        ScreenUtils.mScreenTypeValue = mScreenTypeValue;
    }

    public static String getmScreenTypeValue() {
        return mScreenTypeValue;
    }

    public static void setmScreenAreaValue(String mScreenAreaValue) {
        ScreenUtils.mScreenAreaValue = mScreenAreaValue;
    }

    public static String getmScreenAreaValue() {
        return mScreenAreaValue;
    }

    public static void setmScreenStatusValue(String mScreenStatusValue) {
        ScreenUtils.mScreenStatusValue = mScreenStatusValue;
    }

    public static String getmScreenStatusValue() {
        return mScreenStatusValue;
    }

    public static String getmScreenHotValue() {
        return mScreenHotValue;
    }

    public static void setmScreenHotValue(String mScreenHotValue) {
        ScreenUtils.mScreenHotValue = mScreenHotValue;
    }

    public static String getmScreenLevelValue() {
        return mScreenLevelValue;
    }

    public static void setmScreenLevelValue(String mScreenLevelValue) {
        ScreenUtils.mScreenLevelValue = mScreenLevelValue;
    }

    public static String getmScreenTimeValue() {
        return mScreenTimeValue;
    }

    public static void setmScreenTimeValue(String mScreenTimeValue) {
        ScreenUtils.mScreenTimeValue = mScreenTimeValue;
    }

    public static String getmScreenOrgValue() {
        return mScreenOrgValue;
    }

    public static void setmScreenOrgValue(String mScreenOrgValue) {
        ScreenUtils.mScreenOrgValue = mScreenOrgValue;
    }

    public static String getmScreenLinessValue() {
        return mScreenLinessValue;
    }

    public static void setmScreenLinessValue(String mScreenLinessValue) {
        ScreenUtils.mScreenLinessValue = mScreenLinessValue;
    }
}